package com.tanhua.admin.controller;


import com.alibaba.cloud.commons.lang.StringUtils;
import com.tanhua.admin.service.ManagerService;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    /**
    * 分页查询用户列表
    * */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1")Integer page,
                                @RequestParam(defaultValue = "10")Integer pagesize){
        PageResult result = managerService.findAllUsers(page,pagesize);
        return  ResponseEntity.ok(result);
    }

    /**
     * 根据id查询
     * */
    @GetMapping("/users/{userId}")
    public ResponseEntity findUserById(@PathVariable("userId") Long userId){
        UserInfo userInfo = managerService.findUserById(userId);
        return ResponseEntity.ok(userInfo);
    }

    /**
     * 查询用户发布的所有视频列表
     * */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1")Integer page,
                                 @RequestParam(defaultValue = "10")Integer pagesize,
                                 Long uid){
        PageResult result =managerService.findAllVideos(page,pagesize,uid);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询动态
     * */
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1")Integer page,
                                   @RequestParam(defaultValue = "10")Integer pagesize,
                                   Long uid,String state){
        Integer status = StringUtils.isEmpty(state)|| StringUtils.equals("''",state) ? null : Integer.valueOf(state);
        PageResult result = managerService.findAllMovements(page,pagesize,uid,status);
        return ResponseEntity.ok(result);
    }

    /**
     * 用户冻结
     * */
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody Map params){
       Map map = managerService.userFreeze(params);
       return ResponseEntity.ok(map);
    }

    /**
     * 用户解冻
     * */
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody Map params){
        Map map =managerService.userUnfreeze(params);
        return ResponseEntity.ok(map);
    }


}
